package com.java110.mall.shop.api;

import com.alibaba.fastjson.JSONObject;
import com.java110.dto.convenienceMenus.ConvenienceMenusDto;
import com.java110.po.convenienceMenus.ConvenienceMenusPo;
import com.java110.mall.shop.bmo.convenienceMenus.IDeleteConvenienceMenusBMO;
import com.java110.mall.shop.bmo.convenienceMenus.IGetConvenienceMenusBMO;
import com.java110.mall.shop.bmo.convenienceMenus.ISaveConvenienceMenusBMO;
import com.java110.mall.shop.bmo.convenienceMenus.IUpdateConvenienceMenusBMO;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping(value = "/convenienceMenus")
public class ConvenienceMenusApi {

    @Autowired
    private ISaveConvenienceMenusBMO saveConvenienceMenusBMOImpl;
    @Autowired
    private IUpdateConvenienceMenusBMO updateConvenienceMenusBMOImpl;
    @Autowired
    private IDeleteConvenienceMenusBMO deleteConvenienceMenusBMOImpl;

    @Autowired
    private IGetConvenienceMenusBMO getConvenienceMenusBMOImpl;

    /**
     * 微信保存消息模板
     * @serviceCode /convenienceMenus/saveConvenienceMenus
     * @path /app/convenienceMenus/saveConvenienceMenus
     * @param reqJson
     * @return
     */
    @RequestMapping(value = "/saveConvenienceMenus", method = RequestMethod.POST)
    public ResponseEntity<String> saveConvenienceMenus(@RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue(reqJson, "name", "请求报文中未包含name");
        Assert.hasKeyAndValue(reqJson, "seq", "请求报文中未包含seq");


        ConvenienceMenusPo convenienceMenusPo = BeanConvertUtil.covertBean(reqJson, ConvenienceMenusPo.class);
        return saveConvenienceMenusBMOImpl.save(convenienceMenusPo);
    }

    /**
     * 微信修改消息模板
     * @serviceCode /convenienceMenus/updateConvenienceMenus
     * @path /app/convenienceMenus/updateConvenienceMenus
     * @param reqJson
     * @return
     */
    @RequestMapping(value = "/updateConvenienceMenus", method = RequestMethod.POST)
    public ResponseEntity<String> updateConvenienceMenus(@RequestBody JSONObject reqJson) {

        Assert.hasKeyAndValue(reqJson, "name", "请求报文中未包含name");
        Assert.hasKeyAndValue(reqJson, "seq", "请求报文中未包含seq");
        Assert.hasKeyAndValue(reqJson, "convenienceMenusId", "convenienceMenusId不能为空");


        ConvenienceMenusPo convenienceMenusPo = BeanConvertUtil.covertBean(reqJson, ConvenienceMenusPo.class);
        return updateConvenienceMenusBMOImpl.update(convenienceMenusPo);
    }

    /**
     * 微信删除消息模板
     * @serviceCode /convenienceMenus/deleteConvenienceMenus
     * @path /app/convenienceMenus/deleteConvenienceMenus
     * @param reqJson
     * @return
     */
    @RequestMapping(value = "/deleteConvenienceMenus", method = RequestMethod.POST)
    public ResponseEntity<String> deleteConvenienceMenus(@RequestBody JSONObject reqJson) {
        //Assert.hasKeyAndValue(reqJson, "communityId", "小区ID不能为空");

        Assert.hasKeyAndValue(reqJson, "convenienceMenusId", "convenienceMenusId不能为空");


        ConvenienceMenusPo convenienceMenusPo = BeanConvertUtil.covertBean(reqJson, ConvenienceMenusPo.class);
        return deleteConvenienceMenusBMOImpl.delete(convenienceMenusPo);
    }

    /**
     * 微信删除消息模板
     * @serviceCode /convenienceMenus/queryConvenienceMenus
     * @path /app/convenienceMenus/queryConvenienceMenus
     * @param storeId 小区ID
     * @return
     */
    @RequestMapping(value = "/queryConvenienceMenus", method = RequestMethod.GET)
    public ResponseEntity<String> queryConvenienceMenus(@RequestHeader(value = "store-id") String storeId,
                                                      @RequestParam(value = "page") int page,
                                                      @RequestParam(value = "row") int row) {
        ConvenienceMenusDto convenienceMenusDto = new ConvenienceMenusDto();
        convenienceMenusDto.setPage(page);
        convenienceMenusDto.setRow(row);
        return getConvenienceMenusBMOImpl.get(convenienceMenusDto);
    }


}
